package com.irdstudio.apicenter.console.controller.Platform;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.irdstudio.apicenter.console.controller.MacmsBaseAction;
import com.irdstudio.apicenter.console.startup.MacmsRoot;
import com.irdstudio.apicenter.console.util.MacmsPathUtil;
import com.irdstudio.apicenter.frame.core.jdbc.JdbcBaseDAO;
import com.irdstudio.apicenter.frame.core.jdbc.container.DataList;
import com.irdstudio.apicenter.frame.core.jdbc.container.PageInfo;
import com.irdstudio.apicenter.frame.core.jdbc.tablemodel.ITableModelDAO;
import com.irdstudio.apicenter.frame.util.BeanUtils;

/**
 * 平台公共交易
 * 
 * @author zs.ligm
 * @version 1.0
 * @date 2015-07-21
 */
@Controller
@RequestMapping(value = "/platform")
public class PlatformManagerAction extends MacmsBaseAction {

	/**
	 * 平台公共交易列表
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "publicTradeList")
	public String publicTradeList(HttpServletRequest request) throws Exception {

		// 获取所有参数
		super.getAllRequestData(request);

		// 获取分页参数信息
		PageInfo pageInfo = super.getPageInfo();

		// 查询数据并放入到上下文中
		ITableModelDAO dao = (ITableModelDAO) BeanUtils
				.getBean("tableModelDAO");
		DataList dataList = dao.queryList("select * from app_trade_common",
				pageInfo, null);
		super.context.addDataList("atcList", dataList);
		super.context.addPageInfo("atcList", pageInfo);

		// 将数据上下文放到属性中
		request.setAttribute("context", super.context);

		return "admin/pubTradeList";
	}

	/**
	 * 平台省市地级数据列表
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "areaList")
	public String areaList(HttpServletRequest request) throws Exception {

		// 获取所有参数
		super.getAllRequestData(request);

		// 添加查询条件
		String enname = (request.getParameter("enname") == null) ? "" : request
				.getParameter("enname");
		String cnname = (request.getParameter("cnname") == null) ? "" : request
				.getParameter("cnname");
		String sql = "select * from s_treedic where opttype = 'STD_GB_T3369' and enname like '%"
				+ enname + "%' and cnname like '%" + cnname + "%'";
		request.setAttribute("enname", enname);
		request.setAttribute("cnname", cnname);
		// 获取分页参数信息
		PageInfo pageInfo = super.getPageInfo();

		// 查询数据并放入到上下文中
		ITableModelDAO dao = (ITableModelDAO) BeanUtils
				.getBean("tableModelDAO");
		DataList dataList = dao.queryList(sql, pageInfo, null);
		super.context.addDataList("stdList", dataList);
		super.context.addPageInfo("stdList", pageInfo);

		// 将数据上下文放到属性中
		request.setAttribute("context", super.context);
		return "admin/areaList";
	}

	@RequestMapping(value = "viewPublicTrade")
	public String viewPublicTrade(HttpServletRequest request) throws Exception {

		// 获取所有参数
		super.getAllRequestData(request);
		String tradeCode = request.getParameter("tradeCode");

		// 查询数据并放入到上下文中
		String sql = "select * from app_trade_common where trade_code='"
				+ tradeCode + "'";
		JdbcBaseDAO baseDao = BeanUtils.getBean(JdbcBaseDAO.class);
		request.setAttribute("vtList", baseDao.findMapList(sql, null));
		// 将数据上下文放到属性中
		request.setAttribute("context", super.context);

		return "admin/viewTrade";
	}

	/**
	 * 平台公共参数列表
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "publicPropList")
	public String publicPropList(HttpServletRequest request) throws Exception {

		// 将数据上下文放到属性中
		request.setAttribute("appprj", MacmsPathUtil.getMacmsAppPrjPath(""));
		request.setAttribute("appres", MacmsPathUtil.getMacmsAppResPath(""));
		request.setAttribute("appsrc", MacmsPathUtil.getMacmsAppResPath(""));
		request.setAttribute("svnServerUrl", MacmsRoot.getSvnProjectService()
				.getServerUrl());
		request.setAttribute("svnUserId", MacmsRoot.getSvnProjectService()
				.getSvnUserId());

		return "admin/publicPropList";
	}
}
